<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="org.jbpm.api.ProcessEngine"%>
<%@page import="org.jbpm.api.Configuration"%>

<%@page import="org.jbpm.api.TaskService"%>
<%@page import="java.util.List"%>
<%@page import="org.jbpm.api.task.Task"%>
<%@page import="org.jbpm.api.RepositoryService"%>
<%@page import="java.util.Date"%>
<%@page import="com.su.middleware.util.ThesisUtils"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Submit Master Thesis</title>
</head>
<%
	String authorized = (String) session.getAttribute("authorized");
	String groupID = (String) session.getAttribute("groupid");
	if (authorized == null || !authorized.equals("yes") || 
		groupID == null || !groupID.equals("students"))
	{
%>
	<jsp:forward page="login.jsp">
		<jsp:param name="authorizedPage" value="submitThesis.jsp" />	
		<jsp:param name="desiredGroupID" value="students" />	
	</jsp:forward>
<%
	}
	ProcessEngine engine = new Configuration().buildProcessEngine();
	TaskService ts = engine.getTaskService();
	
	String studentID = (String) session.getAttribute("userid");
	if (studentID == null || studentID.length() == 0) {
		out.println("StudentID should be in the session!");
		return;
	}
	List<Task> tasks = ts.createTaskQuery().processDefinitionId(ThesisUtils.PROCESS_DEFINITION_ID).activityName("write thesis").assignee(studentID).list();
	
	if (tasks.size() == 0 )
	{
	   out.println("No tasks for student ID: " + studentID);
	   out.print("<br/><br/>");
%>
	   <jsp:include page="indexLinks.jsp" />
<% 	   
	}
	else
	{
	   Task task= (Task)tasks.get(0);
	   
	   String title = (String) ts.getVariable(task.getId(), "title");
	   String annotation = (String) ts.getVariable(task.getId(), "annotation");
	   String student = (String) ts.getVariable(task.getId(), "student");
	   String supervisor = (String) ts.getVariable(task.getId(), "supervisor");
%>
<body>
<form action="submitThesis" method="post" enctype="multipart/form-data">
<center>
<table cellpadding="1" cellspacing="2" border="0">
	<tr>
		<th bgcolor="#CCCCFF" colspan="2"><font size="5">MASTER
		THESIS</font> <br />
		</th>
	</tr>
	<tr bgcolor="#c8d8f8">
		<td align="left" colspan="2"><b>Thesis Title</b> <br />
		<textarea name="title" rows="4" cols="60" readonly="readonly"><%=title %></textarea></td>
	</tr>
	<tr bgcolor="#c8d8f8">
		<td align="left" colspan="2"><b>Annotation</b> <br />
		<textarea name="annotation" rows="3" cols="60" readonly="readonly"><%=annotation %></textarea></td>
	</tr>
	<tr bgcolor="#c8d8f8">
		<td align="left" colspan="2"><b>Department</b> <br />
		<textarea name="department" rows="2" cols="60"></textarea></td>
	</tr>
	<tr bgcolor="#c8d8f8">
		<td align="left" colspan="2"><b>Faculty</b> <br />
		<textarea name="faculty" rows="2" cols="60"></textarea></td>
	</tr>
	<tr bgcolor="#c8d8f8">
		<td align="left"><b>Choose file:</b> <br />
		<input type="file" name="uploadFile" size="25"
			maxlength="125" /> <br />
		</td>
	</tr>
	<tr bgcolor="#c8d8f8">
		<td align="left"><b>Student ID</b> <br />
		<input type="text" name="student" size="10" maxlength="10" ></input></td>
		<td align="left"><b>Supervisor ID</b> <br />
		<input type="text" name="supervisor" size="10" value="" maxlength="10" /></td>
	</tr>
	<tr bgcolor="#c8d8f8">
		<td align="center" colspan="2"><input type="submit"
			value="Submit" /> <input type="reset" value="Reset" /></td>
	</tr>
</table>
</center>
<input type="hidden" name="taskId" value="<%out.print(task.getId());%>" />
</form>
<% } %>
</body>
</html>